package com.nineclock.approve.resolver;

import ch.qos.logback.core.joran.action.ActionUtil;
import cn.hutool.json.JSONObject;
import com.google.gson.JsonObject;
import com.nineclock.approve.utils.ActivitiUtils;
import com.nineclock.approve.utils.ApproveExtendsUtils;
import com.nineclock.common.utils.UUIDUtils;
import org.activiti.bpmn.model.Process;
import org.activiti.bpmn.model.SequenceFlow;

// 抽象类, 定义流程节点创建方法, 及公用方法
public abstract class ProcessNodeResolver {
    // 添加节点到流程Process中
    public abstract void addFlowNodeToActiviti(Process process, JSONObject currNode, JSONObject nextNode);

    // 获取当前节点的Key/Id
    protected String getNodeId(JSONObject currNode) {
        String type = currNode.getStr("type");
        String nodeKey = currNode.getStr("nodeKey");
        return ActivitiUtils.getKey(type, nodeKey);
    }
    // 创建流程图中的连线
    protected SequenceFlow newSequenceFlow(Process process, JSONObject currNode, JSONObject nextNode){
        SequenceFlow sequenceFlow = new SequenceFlow();
        sequenceFlow.setId(ActivitiUtils.getKey("seq", UUIDUtils.getUUID()));
        sequenceFlow.setSourceRef(getNodeId(currNode));
        sequenceFlow.setTargetRef(getNodeId(nextNode));
        process.addFlowElement(sequenceFlow);
        return sequenceFlow;
    }
}
